var app = getApp();
Page({
  data: {
    list:[],
    count:0
  },
  onLoad: function (o) {
    this.getInit(o)
  },
  getInit(o){
    var t = this;
    app.request({
      url:getApp().api.siteinfo.apiroot+'/shuidi/goodlist',
      success(e){
        t.setData({list:e.data,count:o.c});
      }
    });
  },
  getGood(e){
    var t = this, item = e.currentTarget.dataset.item;

    wx.request({

      url:getApp().api.siteinfo.apiroot+'shuidi/buy',
      data:{
        goodId:item.id,
        storeId:app.api.siteinfo.acid,
        customerId:wx.getStorageSync('customerId')
      },
      success(e){
        e = e.data;
        if(e.result < 0 ){
          wx.showToast({title:e.message,icon:'none'});
          return;
        }
        wx.showToast({title:'兑换成功',icon:'none'});
        let pages = getCurrentPages(),prevPage = pages[pages.length - 2];
        prevPage.setData({shuidicount:t.data.count-shuidi_count});
        t.setData({count:t.data.count-shuidi_count});
        setTimeout(wx.hideToast,1000);
      }
    });
  }
});